/**
 * @author casazaft
 */
Package("xclab.mvc.patterns").Class("Singleton",{
	Singleton:function(){
		         var thisClass = this.getClass();
        if (typeof thisClass._instance == 'function') 
            thisClass._instance = new thisClass._instance();
        if (thisClass._instance.getInstance() != null) 
            throw Error("Class " + this.Name + thisClass.SINGLETON_MSG);
        thisClass._instance.setInstance(this);
    },
    Statics: {
        _instance: function(){
            var instance = null;
            return {
                getInstance: function(){
                    return instance;
                },
                setInstance: function(p){
                    instance = p;
                }
            }
        },
        SINGLETON_MSG: ' is Singleton',
        getInstance: function(){
            if (typeof this._instance == 'function') 
                this._instance = new this._instance();
            if (this._instance.getInstance() == null) {
				var classRef = this;
				this._instance.setInstance(new classRef(arguments));
			}
                
            return this._instance.getInstance();
        }
    }


});